package com.swipemaster.levelpage;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.swipemaster.R;
import com.swipemaster.achievements.AchievementsManager;
import com.swipemaster.achievements.LevelsInfo;

public class LevelPageActivity extends Activity
{
	private AchievementsManager achievementsManager;

	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.level_page);
		achievementsManager = new AchievementsManager(this);
		LevelsInfo levelsInfo = achievementsManager.getLevelsInfo();
		GridView gridview = (GridView) findViewById(R.id.gridview);
		gridview.setAdapter(new LevelSelectorAdapter(this, levelsInfo));
		gridview.setOnItemClickListener(new OnItemClickListener()
		{
			public void onItemClick(AdapterView<?> parent, View view, int position, long id)
			{
				// TODO: Action after clicking on level selector.
			}
		});
	}

	//TODO better in onPause
	@Override
	protected void onStop()
	{
		super.onStop();
		achievementsManager.saveAchievements();
	}
}